<?php


namespace app\admin\controller;
use app\admin\model\Setting;
use think\Request;

class SettingController extends BaseController
{
    public function index(){
        return $this->fetch();
    }
    public function upd(Request $request){
      $param = input('post.');
      $build_array = [];
      foreach ($param as $key=>$val){
          array_push($build_array,['name'=>$key,'value'=>$val]);
      }
     $setting = new Setting();
     $result =  $setting->saveAll($build_array);
     return json(['code' => 0, 'msg' => '更新成功']);
  }

  public function read(){
      $setting = new Setting();
     $data =  $setting->select();
      $build_array = [];
      foreach ( $data as $key=>$val){
       $build_array[$val['name']] =$val['value'];
      }
      return  json(['code' => 0, 'msg' => '更新成功','data'=>$build_array]);
  }
}
